package com.ruoyi.web.controller.fx;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.fx.FxDistribution;
import com.ruoyi.system.service.fx.IFxDistributionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 分销提成Controller
 *
 * @author ruoyi
 * @date 2024-08-08
 */
@RestController
@RequestMapping("/fx/distribution")
public class FxDistributionController extends BaseController {
    @Autowired
    private IFxDistributionService fxDistributionService;

    /**
     * 查询分销提成列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FxDistribution fxDistribution) {
        startPage();
        List<FxDistribution> list = fxDistributionService.selectFxDistributionList(fxDistribution);
        return getDataTable(list);
    }

    /**
     * 导出分销提成列表
     */
    @Log(title = "分销提成", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FxDistribution fxDistribution) {
        List<FxDistribution> list = fxDistributionService.selectFxDistributionList(fxDistribution);
        ExcelUtil<FxDistribution> util = new ExcelUtil<FxDistribution>(FxDistribution.class);
        util.exportExcel(response, list, "分销提成数据");
    }

    /**
     * 获取分销提成详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(fxDistributionService.selectFxDistributionById(id));
    }

    /**
     * 新增分销提成
     */
    @Log(title = "新增分销", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FxDistribution fxDistribution) {
        return toAjax(fxDistributionService.insertFxDistribution(fxDistribution));
    }

    /**
     * 修改分销提成
     */
    @Log(title = "修改分销", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FxDistribution fxDistribution) {
        return toAjax(fxDistributionService.updateFxDistribution(fxDistribution));
    }

    /**
     * 删除分销提成
     */
    @Log(title = "删除分销", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fxDistributionService.deleteFxDistributionByIds(ids));
    }

    /**
     * 全局统计 （店铺数量，订单数量，商品数量，用户购买商品金额，店铺采购金额）
     * @return
     */
    @GetMapping("/statistics")
    public AjaxResult statistics(){
        return success(fxDistributionService.selectStatistics());
    }
}
